package com.rabbit.controller;

import com.github.pagehelper.PageInfo;
import com.rabbit.annotation.Log;
import com.rabbit.constant.OperType;
import com.rabbit.service.LoginLogService;
import com.rabbit.util.ResultGenUtil;
import com.rabbit.vo.ResultVO;
import com.rabbit.vo.req.LoginLogReq;
import com.rabbit.vo.res.LoginLogRes;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <h1>登录日志管理</h1>
 *
 * @author zjw
 * @date 2022/1/21 10:36
 */
@RestController
@RequestMapping("/loginLog")
public class LoginLogController {

    @Resource
    private LoginLogService loginLogService;

    /**
     * 登录日志列表
     */
    @PostMapping("/list")
    public ResultVO<Object> list(@RequestBody LoginLogReq loginLogReq) {
        PageInfo<LoginLogRes> pageInfo = loginLogService.queryLoginLogList(loginLogReq);
        return ResultGenUtil.genSuccess(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 清空登录日志
     */
    @PostMapping("/truncate")
    @Log(name = "登录日志管理", type = OperType.TRUNCATE)
    public ResultVO<Object> truncate() {
        loginLogService.truncateLoginLog();
        return ResultGenUtil.genSuccess();
    }

    /**
     * 批量删除登录日志
     */
    @PostMapping("/batchDelete")
    @Log(name = "登录日志管理", type = OperType.DELETE)
    public ResultVO<Object> batchDelete(@Validated @RequestBody LoginLogReq loginLogReq) {
        return ResultGenUtil.genSuccess(loginLogService.batchDelete(loginLogReq));
    }

}
